import { gameConfigHandle, propName } from "js/config/gameConfig"
import utils from "js/core/utils"
import { CalcDamageDataModel } from "js/model/battleModel"
import { BuffModel, EffectModel, FighterModel, SkillModel } from "js/model/fighterModel"
import { AttackType, BuffTargetType, BuffType, EffectType, HurtType, MapType, MonsterType, TriggerType } from "js/typeDefine/typeDefine"
import BattleHandle from "./battleHandle"
import fighterHandle from "./fighterHandle"

export class TriggerEffectDataModel {
    damage?: number
    skillID?: number
    skillLvl?: number
    skill: SkillModel
    calcDamageData?: CalcDamageDataModel
    isMutil: boolean
    killAttackTimes: number
    damageRecover: number
    triggerType: TriggerType
    curePer: any
    rangeType: number
    constructor(opts: any = {}) {
        this.damage = opts.damage || 0
        this.skill = opts.skill || null
        this.skillID = opts.skillID
        this.skillLvl = opts.skillLvl
        this.calcDamageData = opts.calcDamageData || {}
        this.isMutil = opts.isMutil || false
        this.damageRecover = opts.damageRecover || 0
        this.killAttackTimes = opts.killAttackTimes || 0
        this.triggerType = opts.triggerType || 0
        this.curePer = opts.curePer || [0, 0]
        this.rangeType = opts.rangeType || 0
    }
}


export default class BattleSkillHandle {
    battleHandle: BattleHandle
    skillTimers: {}
    constructor(battleHandle: BattleHandle) {
        this.battleHandle = battleHandle
        this.skillTimers = {}
    }

    async startUseSkill(attacker: FighterModel, skill: SkillModel, isTeam: boolean = false) {
        this.battleHandle.startUseSkillAnimation(skill.skillID, attacker.battlePos, skill.cd / 1000)
        let timerID = this.battleHandle.timerHandle.setTimeout(() => {
            if (skill.triggerLimitTimes && skill.triggerTimes >= skill.triggerLimitTimes) {
                return
            }

            let triggerEffectData1 = new TriggerEffectDataModel()
            triggerEffectData1.skillID = skill.skillID
            triggerEffectData1.skillLvl = skill.skillLvl
            triggerEffectData1.skill = skill

            this.battleHandle.fighterNodeUpdate(attacker.tID)
            this.battleHandle.cdAnimation(attacker.indexID)
            this.triggerEffects(attacker, TriggerType.UseSkill, null, triggerEffectData1)
            if (skill.triggerLimitTimes) {
                skill.triggerTimes += 1
            }
            if (skill.doubleTriggerPer > 0) {
                if (this.battleHandle.rand.intn(100) <= skill.doubleTriggerPer) {
                    let triggerEffectData1 = new TriggerEffectDataModel()
                    triggerEffectData1.skillID = skill.skillID
                    triggerEffectData1.skillLvl = skill.skillLvl
                    triggerEffectData1.skill = skill
                    this.triggerEffects(attacker, TriggerType.UseSkill, null, triggerEffectData1)
                    this.battleHandle.skillTipAnimation(skill.skillID, "多重")
                }
            }
            this.startUseSkill(attacker, skill)
        }, () => {
            if (isTeam && skill.triggerTimes <= 1) {
                return skill.firstCd || 3000
            }
            return (skill.cd - (attacker.skillsReduceCd[skill.skillID] || 0)) / (this.battleHandle.timerHandle.timeCoe || 1)
        })
        attacker.timerObject[`${attacker.battlePos}_${skill.skillID}`] = timerID
        this.skillTimers[`${attacker.battlePos}_${skill.skillID}`] = timerID
    }

    getNeedAnger = (skill: SkillModel) => {
        let jjLvl = fighterHandle.getSkillLvl(skill.skillLvl)
        let anger = 0
        let skillConfig = gameConfigHandle.configByID[skill.skillID]
        if (skillConfig.needAnger) {
            anger = utils.getIncValue(skillConfig.needAnger, jjLvl - 1)
        }
        let needAnger = anger - skill.reduceAnger
        return needAnger
    }

    playSkill(attacker: FighterModel) {
        for (let i = attacker.waitSkills.length - 1; i >= 0; i--) {
            if (attacker.battleAttri.hp < 1) {
                return
            }
            let skill = attacker.waitSkills[i]

            let needAnger = this.getNeedAnger(skill)
            if (attacker.anger >= needAnger) {
                attacker.anger -= needAnger
                let triggerEffectData1 = new TriggerEffectDataModel()
                triggerEffectData1.skillID = skill.skillID
                triggerEffectData1.skillLvl = skill.skillLvl
                triggerEffectData1.skill = skill
                this.triggerEffects(attacker, TriggerType.UseSkill, null, triggerEffectData1)
                if (skill.doubleTriggerPer > 0) {
                    if (this.battleHandle.rand.intn(100) <= skill.doubleTriggerPer) {
                        let triggerEffectData1 = new TriggerEffectDataModel()
                        triggerEffectData1.skillID = skill.skillID
                        triggerEffectData1.skillLvl = skill.skillLvl
                        triggerEffectData1.skill = skill
                        this.triggerEffects(attacker, TriggerType.UseSkill, null, triggerEffectData1)
                        this.battleHandle.skillTipAnimation(skill.skillID, "多重")
                    }
                }
                this.startUseSkill(attacker, skill)
                attacker.waitSkills.splice(i, 1)
            }
        }

    }

    async triggerEffects(trigger: FighterModel, type: TriggerType, target: FighterModel, triggerEffectData: TriggerEffectDataModel) {
        let effects = trigger?.effects[type]
        if (effects) {
            for (let i = 0; i < effects.length; i++) {
                let effect: any = effects[i]
                effect.skillLvl = triggerEffectData.skillLvl || 1
                if (effect.skillID == triggerEffectData.skillID || effect.skillID == triggerEffectData.calcDamageData.skillID) {
                    triggerEffectData.triggerType = type
                    await this.triggerEffect(trigger, target, effect, triggerEffectData)
                }
            }
        }
    }

    async triggerEffect(trigger: FighterModel, target: FighterModel, event: EffectModel, triggerEffectData: TriggerEffectDataModel) {
        let jjLvl = Math.floor((event.skillLvl - 1) / 10) + 1
        let triggerTypeRate = event.data.triggerPer ? utils.getIncValue(event.data.triggerPer, jjLvl - 1) : 100
        if (this.battleHandle.rand.intn(100) > triggerTypeRate) {
            return
        }
        if (event.data.buff) {
            let buff = event.data.buff
            if (buff.buffTargetType == BuffTargetType.MySelf) {
                let buffID = buff.buffID
                this.addBuff(trigger, trigger, buffID, event.skillLvl, 1 + triggerEffectData.skill.addBuff)
            } else if (buff.buffTargetType == BuffTargetType.AttackTarget) {
                let buffID = buff.buffID
                this.addBuff(trigger, target, buffID, event.skillLvl, 1 + triggerEffectData.skill.addDeBuff)
            } else if (buff.buffTargetType == BuffTargetType.Partner) {
                this.battleHandle.playSound("addBuff")
                let buffID = buff.buffID
                this.addBuff(trigger, target, buffID, event.skillLvl, 1 + triggerEffectData.skill.addDeBuff)
            } else if (buff.buffTargetType == BuffTargetType.MyTeam) {
                this.battleHandle.playSound("addBuff")
                let buffID = buff.buffID
                let buffAmount = utils.getIncValue(buff.buffAmount || [1, 0], event.skillLvl - 1)
                let sortTeam = this.battleHandle[`team${trigger.teamID}`]
                    .filter(f => f != null && f.battleAttri.hp > 0)
                    .sort((f1, f2) => f2.battleAttri.maxHp - f1.battleAttri.maxHp)
                let buffFighters = sortTeam.slice(0, buffAmount)
                for (let i = 0; i < buffFighters.length; i++) {
                    const buffFighter = buffFighters[i];
                    this.battleHandle.fighterNodes[buffFighter.indexID]?.permanenceEffectAnimation(EffectType.Shield)
                    this.addBuff(trigger, buffFighter, buffID, event.skillLvl, 1 + triggerEffectData.skill.addBuff)
                }
            }
        } else if (event.data.damageRecoverHpPer) {
            let per = utils.getIncValue(event.data.damageRecoverHpPer, event.skillLvl - 1)
            let value = Math.floor(per * triggerEffectData.damageRecover / 100)
            if (value < 1) { value = 1 }
            triggerEffectData.calcDamageData.addHpName = event.data.name
            this.battleHandle.addHp(trigger, value, triggerEffectData.calcDamageData)
            this.battleHandle.playSound("recover")
        } else if (event.data.curePer) {
            triggerEffectData.calcDamageData.addHpName = event.data.name
            triggerEffectData.calcDamageData.attacker = trigger
            let sortTeam = this.battleHandle[`team${trigger.teamID}`]
                .filter(f => f != null && f.battleAttri.hp > 0 && f.indexID != trigger.indexID)
                .sort((f1, f2) => f1.battleAttri.hp - f2.battleAttri.hp)
            let cureAmount = utils.getIncValue((event.data.cureAmount || [1, 0]), event.skillLvl - 1)
            let cureFighters = sortTeam.slice(0, cureAmount)
            for (let i = 0; i < cureFighters.length; i++) {
                const cureFighter = cureFighters[i];
                let cureValue = Math.floor(cureFighter.battleAttri.maxHp * utils.getIncValue(event.data.curePer, event.skillLvl - 1) / 100)
                this.battleHandle.addHp(cureFighter, cureValue, triggerEffectData.calcDamageData)
                this.battleHandle.playSound("recover")
                this.battleHandle.skillAttackAnimation(event.skillID, trigger.battlePos, trigger.indexID)
            }
        } else if (event.data.recoverPer) {
            triggerEffectData.calcDamageData.addHpName = event.data.name
            let cureValue = Math.floor(trigger.battleAttri.maxHp * utils.getIncValue(event.data.recoverPer, event.skillLvl - 1) / 100)
            this.battleHandle.addHp(trigger, cureValue, triggerEffectData.calcDamageData)
            this.battleHandle.playSound("recover")
        } else if (event.data.damageRecoverPartnerHpPer) {
            triggerEffectData.calcDamageData.addHpName = event.data.name
            let cureValue = Math.floor(triggerEffectData.damageRecover * utils.getIncValue(event.data.damageRecoverPartnerHpPer, 1) / 100)
            this.battleHandle.addHp(trigger, cureValue, triggerEffectData.calcDamageData)
            this.battleHandle.playSound("recover")
        } else if (event.data.addPartnerAnger) {
            this.addAnger(target, utils.getIncValue(event.data.addPartnerAnger, 1))
            this.battleHandle.playSound("addAnger")
        } else if (event.data.shield) {
            let shieldPer = utils.getIncValue(event.data.shield, event.skillLvl - 1)
            let shieldValue = Math.floor(trigger.battleAttri.maxHp * shieldPer / 100)
            //护盾往上叠,上限为生命值的50%
            trigger.battleAttri.shield += shieldValue
            if (this.battleHandle.mapID) {
                let mapComfig = gameConfigHandle.configByID[this.battleHandle.mapID]
                if (mapComfig.mapType == MapType.Fantasy) {
                    let coe = 0.5
                    if (trigger.type == MonsterType.Boss) {
                        coe = 0.05
                    } else if (trigger.type == MonsterType.Lord) {
                        coe = 0.1
                    } else if (trigger.type == MonsterType.Elite) {
                        coe = 0.2
                    } else if (trigger.type == MonsterType.Partner) {
                        coe = 1
                    }
                    let maxShield = Math.floor(coe * trigger.battleAttri.maxHp)
                    trigger.battleAttri.shield = trigger.battleAttri.shield > maxShield ? maxShield : trigger.battleAttri.shield
                }
            }
            this.battleHandle.fighterNodeUpdate(trigger.indexID)
            this.battleHandle.playSound("addShield")
            this.battleHandle.fighterNodes[trigger.indexID]?.permanenceEffectAnimation(EffectType.Shield)
            this.battleHandle.skillAttackAnimation(event.skillID, trigger.battlePos, trigger.indexID)
        } else if (event.data.skillHurtPer) {
            let idx = jjLvl > event.data.attackAmount.length ? event.data.attackAmount.length : jjLvl
            let attackAmount = event.data.attackAmount[idx - 1]
            let hitRange
            if (event.data.hitRange) {
                hitRange = event.data.hitRange[jjLvl - 1]
            }
            let rangeType
            if (event.data.rangeType) {
                rangeType = event.data.rangeType
            }
            let defenders = this.battleHandle.calcHarted(trigger, attackAmount, hitRange, event.data.hatredType, triggerEffectData.skill.highLevel, rangeType)
            this.battleHandle.skillAttackAnimation(event.skillID, trigger.battlePos, trigger.indexID)
            let totalDamage = 0
            let triggerEffectData1 = new TriggerEffectDataModel()
            triggerEffectData1.skillID = event.skillID
            triggerEffectData1.skillLvl = event.skillLvl
            triggerEffectData1.skill = triggerEffectData.skill
            triggerEffectData1.isMutil = triggerEffectData.isMutil

            this.triggerEffects(trigger, TriggerType.UseSkillDamagePre1, null, triggerEffectData1)
            let attackTimes = 1
            if (event.data.attackTimes) {
                attackTimes = event.data.attackTimes[jjLvl - 1]
            }
            let baseHurtPer = 0
            if (trigger.skillsHurtPer[event.skillID]) {
                baseHurtPer = trigger.skillsHurtPer[event.skillID]
            }
            for (let i = 0; i < defenders.length; i++) {
                let defender = defenders[i]
                for (let j = 0; j < attackTimes; j++) {
                    this.triggerEffects(trigger, TriggerType.UseSkillDamagePre2, defender, triggerEffectData1)
                    let damageData = new CalcDamageDataModel()
                    damageData.attacker = trigger
                    damageData.attackType = AttackType.Skill
                    damageData.hurtType = event.data.hurtType || HurtType.Normal
                    let skillHurtPer = utils.getIncValue(event.data.skillHurtPer, event.skillLvl - 1)

                    damageData.attackHurtCoe = skillHurtPer + baseHurtPer
                    damageData.skillID = triggerEffectData.skillID
                    damageData.skillLvl = triggerEffectData.skillLvl
                    damageData.skill = triggerEffectData.skill
                    damageData.decHpAnimationDelay = j * 80 + triggerEffectData.killAttackTimes * 80
                    if (event.data.increaseHurtPer) {
                        let increaseHurtPer = utils.getIncValue(event.data.increaseHurtPer, i)
                        damageData.hurtInc = increaseHurtPer
                    }
                    let isDodge = await this.battleHandle.isDodge(trigger, defender)
                    if (isDodge) {
                        this.battleHandle.beAttackAnimation(defender.indexID, 0, propName[event.skillID] + '闪', damageData.hurtType)
                        let triggerEffectData1 = new TriggerEffectDataModel()
                        await this.triggerEffects(defender, TriggerType.DodgeAfter, defender, triggerEffectData1)
                    } else {

                        let { hurt, isCrit } = await this.battleHandle.calcDamage(trigger, defender, damageData)
                        this.battleHandle.decHp(defender, hurt, damageData, triggerEffectData.killAttackTimes)
                        if (triggerEffectData1.damageRecover == 0) {
                            triggerEffectData1.damageRecover = hurt
                        }
                        totalDamage += hurt
                    }


                }
            }
            triggerEffectData1.damage = totalDamage
            this.triggerEffects(trigger, TriggerType.UseSkillDamageAfter, null, triggerEffectData1)
            if (trigger.type == MonsterType.Partner) {
                this.battleHandle.playSound("skillAttack")
            } else {
                this.battleHandle.playSound("petAttack")
            }

        } else if (event.data.reduceSkillCd) {
            let list = trigger.skills.filter(skill => {
                if (skill.skillID !== event.skillID) {
                    return skill
                }
            })
            if (list.length > 0) {
                let skill = utils.getOneFromArray(list, this.battleHandle.rand)
                let skillID = skill.skillID
                let timerID = this.skillTimers[`${trigger.battlePos}_${skillID}`]
                let skillConfig = gameConfigHandle.configByID[skill.skillID]
                let currentTime = this.battleHandle.timerHandle.getTime()
                let endTime = this.battleHandle.timerHandle.getTimerEndTime(timerID)
                let interval = endTime - currentTime - event.data.reduceSkillCd
                if (interval < 0) {
                    interval = 0
                }
                this.battleHandle.timerHandle.clearTimeout(timerID)
                this.battleHandle.skillStopAnimation(skillID, (skillConfig.cd - interval) / 1000)
                this.skillTimers[`${trigger.battlePos}_${skill.skillID}`] = this.battleHandle.timerHandle.setTimeout(() => {
                    let triggerEffectData1 = new TriggerEffectDataModel()
                    triggerEffectData1.skillID = skill.skillID
                    triggerEffectData1.skillLvl = skill.skillLvl
                    triggerEffectData1.skill = skill
                    this.triggerEffects(trigger, TriggerType.UseSkill, null, triggerEffectData1)
                    this.startUseSkill(trigger, skill)
                }, interval)
            }
        } else if (event.data.mutil) {
            if (!triggerEffectData.isMutil) {
                let triggerEffectData1 = new TriggerEffectDataModel()
                triggerEffectData1.skillID = triggerEffectData.skillID
                triggerEffectData1.skillLvl = triggerEffectData.skillLvl
                triggerEffectData1.skill = triggerEffectData.skill
                triggerEffectData1.isMutil = true
                this.triggerEffects(trigger, TriggerType.UseSkill, null, triggerEffectData1)
            }
        } else if (event.data.killAttackAgain) {
            let killAttackTimes = triggerEffectData.killAttackTimes
            if (killAttackTimes < event.data.attackTimesMax) {
                let triggerEffectData1 = new TriggerEffectDataModel()
                triggerEffectData1.skillID = triggerEffectData.skillID
                triggerEffectData1.skillLvl = triggerEffectData.skillLvl
                triggerEffectData1.skill = triggerEffectData.skill
                triggerEffectData1.killAttackTimes = killAttackTimes + 1
                this.triggerEffects(trigger, TriggerType.UseSkill, null, triggerEffectData1)
            }
        } else if (event.data.addSkillAttris) {
            Object.entries(event.data.addSkillAttris).forEach(attriItem => {
                let name = attriItem[0]
                let values: any = attriItem[1]
                triggerEffectData.skill[name] += utils.getIncValue(values, triggerEffectData.skillLvl - 1)
            })

        } else if (event.data.riskLifePer) {
            if (trigger.battleAttri.hp / trigger.battleAttri.maxHp * 100 >= event.data.riskLifePer) {
                let hurt = trigger.battleAttri.maxHp * event.data.consumehpPer / 100
                let damageData = new CalcDamageDataModel()
                damageData.decHpName = event.data.name
                this.battleHandle.decHp(trigger, hurt, damageData)
                let buff = event.data.addbuff
                let triggerTypeRate = event.data.triggerPer ? utils.getIncValue(event.data.triggerPer, event.skillLvl - 1) : 100
                if (buff.buffTargetType == BuffTargetType.MySelf) {
                    let buffID = buff.buffID
                    this.addBuff(trigger, trigger, buffID, event.skillLvl, 1 + triggerEffectData.skill.addBuff)
                }
            }
        }
    }

    addBuff(deliver: FighterModel, affecteder: FighterModel, buffID: number, buffLvl: number, addStack: number = 1) {
        let buffConfig = gameConfigHandle.configByID[buffID]
        let buff = new BuffModel({
            buffID: buffID,
            lvl: buffLvl,
            stack: buffConfig.stack ? addStack : 0,
            DeliverIndex: deliver.indexID,
        })
        if (!affecteder) {
            return
        }
        let index = affecteder.buffs.findIndex(item => item.buffID == buffID)
        let maxStack = !buffConfig.stack ? 0 : utils.getIncValue(buffConfig.stack, buffLvl - 1)
        if (index == -1) {
            affecteder.buffs.push(buff)
            this.battleHandle.fighterNodes[affecteder.indexID]?.permanenceEffectAnimation(EffectType.Speed)
        } else {
            if (maxStack > 0) {
                affecteder.buffs[index].stack += addStack
                if (affecteder.buffs[index].stack >= maxStack) {
                    affecteder.buffs[index].stack = maxStack
                }
            } else {
                let originBuff = affecteder.buffs[index]
                if (originBuff.timerID !== 0) {
                    this.battleHandle.timerHandle.clearTimeout(originBuff.timerID)
                }
                affecteder.buffs[index] = buff
            }
        }
        fighterHandle.calcBattleFighterAttri(affecteder)
        this.battleHandle.fighterNodeUpdate(affecteder.indexID)
        if (maxStack == 0) {
            let timerID = this.battleHandle.timerHandle.setTimeout(() => {
                this.clearBuffBybuffID(affecteder, buffID)
            }, buffConfig.cd)
            buff.timerID = timerID
            affecteder.timers.push(timerID)
        }
        if (buffConfig.triggerCd && index == -1) {
            let triggerTimerID = this.battleHandle.timerHandle.setInterval(() => {
                this.triggerBuff(affecteder, buff)
            }, buffConfig.triggerCd)
            buff.triggerTimerID = triggerTimerID
            affecteder.timers.push(triggerTimerID)
        }
    }

    clearBuffBybuffID(fighter: FighterModel, buffID: number) {
        let index = fighter.buffs.findIndex(buff => {
            if (buff.buffID == buffID) {
                return true
            }
        })
        if (index !== -1) {
            let buff = fighter.buffs[index]
            fighter.buffs.splice(index, 1)
            if (buff.timerID !== 0) {
                this.battleHandle.timerHandle.clearTimeout(buff.timerID)
                let index = fighter.timers.findIndex(timerID => timerID == buff.timerID)
                if (index !== -1) {
                    fighter.timers.splice(index, 1)
                }
            }
            if (buff.triggerTimerID !== 0) {
                this.battleHandle.timerHandle.clearTimeout(buff.triggerTimerID)
                let index = fighter.timers.findIndex(timerID => timerID == buff.triggerTimerID)
                if (index !== -1) {
                    fighter.timers.splice(index, 1)
                }
            }
            fighterHandle.calcBattleFighterAttri(fighter)
            this.battleHandle.fighterNodeUpdate(fighter.indexID)
        }
    }

    triggerBuff(affecteder: FighterModel, buff: BuffModel) {
        let buffConfig = gameConfigHandle.configByID[buff.buffID]
        if (buffConfig.buffType == BuffType.Poison) {
            this.calcPoison(affecteder, buff)
        } else if (buffConfig.buffType == BuffType.Blood) {
            this.calcBlood(affecteder, buff)
        } else if (buffConfig.buffType == BuffType.Fire) {
            this.calcFire(affecteder, buff)
        }
    }

    calcPoison(affecteder: FighterModel, buff: BuffModel) {
        let buffConfig = gameConfigHandle.configByID[buff.buffID]
        let poisonHurt = utils.getIncValue(buffConfig.poisonHurt, buff.stack, true)

        // let damage = Math.floor(affecteder.battleAttri.maxHp * poisonHurt / 100)
        //boss免疫中毒伤害
        if (affecteder.type == MonsterType.Boss || affecteder.type == MonsterType.FantasyBoss) {
            return
        }
        
        if (affecteder.type == MonsterType.FantasyMonster) {
            poisonHurt = poisonHurt / 20
        }
        if (affecteder.type == MonsterType.Lord) {
            poisonHurt = poisonHurt / 10
        }
        if (affecteder.type == MonsterType.Elite) {
            poisonHurt = poisonHurt / 2
        }

        let damage = Math.floor(affecteder.battleAttri.hp * poisonHurt / 100)
        let damageData = new CalcDamageDataModel()
        damageData.decHpName = buffConfig.name
        this.battleHandle.decHp(affecteder, damage, damageData)
    }

    calcFire(affecteder: FighterModel, buff: BuffModel) {
        let buffConfig = gameConfigHandle.configByID[buff.buffID]
        let fireHurt = utils.getIncValue(buffConfig.fireHurt || [1, 0], buff.stack, true)

        // let damage = Math.floor(affecteder.battleAttri.maxHp * poisonHurt / 100)
        //boss免疫中毒伤害
        if (affecteder.type == MonsterType.Boss || affecteder.type == MonsterType.FantasyBoss) {
            return
        }
        
        if (affecteder.type == MonsterType.FantasyMonster) {
            fireHurt = fireHurt / 20
        }
        if (affecteder.type == MonsterType.Lord) {
            fireHurt = fireHurt / 10
        }
        if (affecteder.type == MonsterType.Elite) {
            fireHurt = fireHurt / 2
        }

        let damage = Math.floor(affecteder.battleAttri.maxHp * fireHurt / 100) || 1
        let damageData = new CalcDamageDataModel()
        damageData.decHpName = buffConfig.name
        this.battleHandle.decHp(affecteder, damage, damageData)
    }

    calcBlood(affecteder: FighterModel, buff: BuffModel) {
        let buffConfig = gameConfigHandle.configByID[buff.buffID]
        let damage = Math.floor(affecteder.battleAttri.maxHp * buffConfig.bloodHurtPer / 100)
        if (affecteder.type == MonsterType.Boss || affecteder.type == MonsterType.FantasyBoss) {
            //boss流血免疫
            return
        }
        if (affecteder.type == MonsterType.FantasyMonster) {
            damage = Math.floor(affecteder.battleAttri.maxHp * buffConfig.bloodHurtPer / 2000)
        }
        if (affecteder.type == MonsterType.Lord) {
            //黄怪流血削弱到1/10
            damage = Math.floor(affecteder.battleAttri.maxHp * buffConfig.bloodHurtPer / 1000)
        }
        let damageData = new CalcDamageDataModel()
        damageData.decHpName = buffConfig.name
        this.battleHandle.decHp(affecteder, damage, damageData)
    }


    async addAnger(attacker: FighterModel, angerValue: number) {
        attacker.anger += angerValue
        if (attacker.anger > attacker.battleAttri.angerMax) {
            attacker.anger = attacker.battleAttri.angerMax
        }
        await this.battleHandle.fighterNodeUpdate(attacker.indexID)
        await this.playSkill(attacker)
    }
}